// pages/my/feedbackDetail/feedbackDetail.js
const app=getApp();
const util = require("../../../utils/util");
const moment = require("../../../utils/moment");
import Toast from '../../../miniprogram_npm/@vant/weapp/toast/toast';
Page({

  /**
   * 页面的初始数据
   */
  data: {
    questionData:[],
    feedbackData:[],
    feedBackId:'',
    isFullSucreen: app.globalData.isFullSucreen ? true : false, //判断机型
  },
  // 问题已解决
  questionOver(){
    let that=this
    let params={
      feedbackId:that.data.feedBackId
    }
    util.postToken('/wechat/feedback/done',params,that.data.token,function (res) {
      console.log('问题已解决',res)
      if (res.status_code==200) {
        console.log('成功')
        Toast.success('成功')
        wx.navigateTo
      } else {
        
      }
    })
  },
  // 继续反馈
  feedbackContinue(){
    wx.navigateTo({
      url:'../feedbackContinue/feedbackContinue?id='+this.data.feedBackId
    })
  },
  // 获取问题类别
  getQuestionData(){
    let that=this
    util.postRes("/wechat/feedback/question/types", {}, function (res) {
      console.log(typeof res);
      let arr = [];
      for (let i in res) {
        arr.push({
          id: i,
          name: res[i],
        });
      }
      console.log(arr);
      that.setData({
        questionData: arr,
      });
    });
  },
  concatStr(str) {
    console.log("刚开始", str);
    console.log(typeof str);
    let that = this;
    let questionData = that.data.questionData;
    // let str = "1,4,5,7";
    let arr = str.split(",");
    let arr1 = [];
    for (let i = 0; i < arr.length; i++) {
      let index = arr[i] - 1;
      arr1.push(questionData[index].name);
    }
    console.log(arr1);
    console.log(arr1.join(","));
    return arr1.join(",");
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var token = wx.getStorageSync("token");
    let that = this;
    this.setData({
      token,
      feedBackId:options.id
    });
    console.log('路由传递过来的',options.id)
    let params={
      feedBackId:options.id
    }
    that.getQuestionData()
    util.getToken('/wechat/feedback/info',params,that.data.token,function (res) {
      console.log('res',res.data)
      let arr=res.data
      arr.questionType=that.concatStr(arr.questionType) ;
      arr.createDate= moment(arr.createDate).format("MM/DD hh:mm");
      arr.modifyDate= moment(arr.modifyDate).format("MM/DD hh:mm");
      that.setData({
        feedbackData:res.data
      })

    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})